package com.kaka.bus.engine.home.info.borrowlist.deteil;

import com.kaka.bus.bean.BorrowDeteil;
import com.kaka.bus.bean.BorrowList;
import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by OnionMac on 2018/1/3.
 */

public class BorrowDeteilPresenter extends RxPresenter<BorrowDeteilContract.View> implements BorrowDeteilContract.Presenter {

    @Inject
    public BorrowDeteilPresenter(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public void getBorrowDeteil(String userId, String token, String borrowId) {
        mView.showDialog("稍等~");
        addSubscribe(mDataManager
                .getApi()
                .getBorrowDeteil(borrowId)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<BorrowDeteil>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<BorrowDeteil> data) {
                           mView.getDeteilResult(data);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                }));
    }

    @Override
    public void cancelRequest(String userId, String token,String borr_id){
        addSubscribe(mDataManager.getApi()
                .cancelRquest(userId,borr_id,token)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<List<BorrowList>>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<List<BorrowList>> data) {
                        mView.refresh();
                    }
                    @Override
                    protected void onFaild() {
                    }
                }));
    }
}
